/**
 * @Author MrLi
 * @Version 1.0
 * @Date 2023-08-10 13:43:26
 */
package com.cl.erp_2301.controller;

import com.cl.erp_2301.Service.StoreOperService;
import com.cl.erp_2301.dto.DataDTO;
import com.cl.erp_2301.dto.StoreOperDTO;
import com.cl.erp_2301.entity.Emp;
import com.cl.erp_2301.entity.Goods;
import com.cl.erp_2301.entity.Store;
import com.cl.erp_2301.util.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*/v2/storeoper/emp_list*/
@RestController
@RequestMapping("/v2")
public class StoreOperController {

    @Resource
    private StoreOperService storeOperService;

    @ResponseBody
    @RequestMapping("/storeoper/emp_list")
    public Result empList(){
        List<Emp> empList = storeOperService.empList();
        return Result.okRows(empList);
    }

    @ResponseBody
    @RequestMapping("/storeoper/goods_list")
    public Result GoodsList(){
        List<Goods> goodsList = storeOperService.goodsList();
        return Result.okRows(goodsList);
    }

    @ResponseBody
    @RequestMapping("/storeoper/store_list")
    public Result StoreList(){
        List<Store> goodsList = storeOperService.storeList();
        return Result.okRows(goodsList);
    }


    @RequestMapping(value = "/storeoper", method = RequestMethod.GET)
    public Result findAll(StoreOperDTO storeOperDTO, int page, int rows, HttpSession session){
        Page<Object> page1 = PageHelper.startPage(page,rows);
        String username = (String) session.getAttribute("username");
        storeOperDTO.setEmpName(username);
        List<StoreOperDTO> storeDtoList  = storeOperService.findAll(storeOperDTO);
        DataDTO data1 = new DataDTO();
        data1.setRows(storeDtoList);
        data1.setTotal(page1.getTotal());
        return Result.ok(data1);
    }
}
